package ace.module.captcha.core.impl.controller.rest.client;

import ace.cmp.core.model.R;
import ace.module.captcha.api.model.dto.CaptchaImageDto;
import ace.module.captcha.api.model.input.CaptchaCreateInput;
import ace.module.captcha.core.impl.model.request.CaptchaCreateByAppKeyRequest;
import ace.module.captcha.core.impl.service.CaptchaImageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Caspar 客户端入口
 */
@Tag(name = "验证码服务-客户端-图形验证码")
@AllArgsConstructor
@RestController
@Slf4j
public class CaptchaImageClientController {

  public static final String PATH_BASE = "/captcha/image/client";
  public static final String PATH_CREATE_BY_APP_KEY = "/createByAppKey";
  public static final String PATH_CREATE_BY_APP_ID = "/createByAppId";
  public static final String URI_CAPTCHA_IMAGE_CREATE_BY_APP_KEY = PATH_BASE + PATH_CREATE_BY_APP_KEY;
  public static final String URI_CAPTCHA_IMAGE_CREATE_BY_APP_ID = PATH_BASE + PATH_CREATE_BY_APP_ID;
  private final CaptchaImageService captchaImageService;

  @Operation(summary = "获取图形验证码", description = "data是base 64 图片数据.example: base64, dkyw148asfl")
  @PostMapping(URI_CAPTCHA_IMAGE_CREATE_BY_APP_KEY)
  public R<CaptchaImageDto> createBase64ByAppKey(@Valid @RequestBody CaptchaCreateByAppKeyRequest request) {
    CaptchaImageDto resultDTO = captchaImageService.createBase64ByAppKey(request.getCaptchaAppKey());
    return R.ok(resultDTO);
  }

  @Operation(summary = "获取图形验证码", description = "data是base 64 图片数据.example: base64, dkyw148asfl")
  @PostMapping(URI_CAPTCHA_IMAGE_CREATE_BY_APP_ID)
  public R<CaptchaImageDto> createBase64(@Valid @RequestBody CaptchaCreateInput request) {
    CaptchaImageDto resultDTO = captchaImageService.createBase64(request.getCaptchaAppId());
    return R.ok(resultDTO);
  }
}
